package com.diaohw.module.file.controller;

import com.diaohw.module.file.obj.query.FileQuery;
import com.diaohw.module.file.obj.vo.FileVO;
import com.diaohw.module.file.service.FileService;
import com.diaohw.platform.common.obj.page.PageResultVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 文件信息 前端控制器
 * </p>
 *
 * @author D-Hw
 * @since 2024-09-20
 */
@Tag(name = "文件信息")
@RestController
@RequestMapping("/file")
public class FileController {

    @Resource
    private FileService service;

    @Operation(summary = "文件上传")
    @PostMapping("/{bucket}")
    public FileVO upload(@PathVariable("bucket") String bucket, @RequestPart("file") MultipartFile file) {
        return service.upload(bucket, file);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除")
    public Boolean delete(@PathVariable("id") String id) {
        return service.delete(id);
    }

    @GetMapping("/info/{id}")
    @Operation(summary = "依据ID查看信息")
    public FileVO info(@PathVariable("id") String id) {
        return service.info(id);
    }

    @GetMapping("/{id}")
    @Operation(summary = "依据ID查看信息")
    public void detail(@PathVariable("id") String id) {
        service.detail(id);
    }

    @GetMapping
    @Operation(summary = "查询列表")
    public List<FileVO> all(FileQuery query) {
        return service.findByList(query);
    }

    @GetMapping("/page")
    @Operation(summary = "分页查看")
    public PageResultVo<FileVO> page(FileQuery query) {
        return service.findByPage(query);
    }

    @GetMapping("/ext")
    @Operation(summary = "文件后缀查询")
    public List<String> ext() {
        return service.ext();
    }

}
